package com.xydtech.ecard.ecard.service.impl;

import com.xydtech.common.utils.AESEncryptionUtils;
import com.xydtech.common.utils.StringUtils;
import com.xydtech.ecard.ecard.domain.EcardApiExperienceApprove;
import com.xydtech.ecard.ecard.mapper.EcardApiExperienceApproveMapper;
import com.xydtech.ecard.ecard.service.IEcardApiExperienceApproveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 电子名片用户申请体验审批记录Service业务层实现类
 *
 * @author yuzhiguo
 * @date 2024-10-23 上午10:26
 */
@Service
public class EcardApiExperienceApproveServiceImpl implements IEcardApiExperienceApproveService {

    @Autowired
    private EcardApiExperienceApproveMapper ecardExperienceApproveMapper;

    /**
     * 新增电子名片申请体验审批记录
     * @param ecardExperienceApprove
     * @return
     */
    @Override
    public int insertEcardExperienceApprove(EcardApiExperienceApprove ecardExperienceApprove) {
        return ecardExperienceApproveMapper.insertEcardExperienceApprove(ecardExperienceApprove);
    }

    /**
     * 条件查询用户申请体验审批记录列表
     * @param experienceApprove
     * @return
     */
    @Override
    public List<EcardApiExperienceApprove> getApproveExperienceList(EcardApiExperienceApprove experienceApprove, String salt) {
        try {
            //数据加密（手机号、身份证号）
            if (!StringUtils.objIsNullOrEmpty(experienceApprove.getExpPhone())) {
                experienceApprove.setExpPhone(AESEncryptionUtils.encrypt(experienceApprove.getExpPhone(), salt));
            }
            List<EcardApiExperienceApprove> experienceApproveList = ecardExperienceApproveMapper.getApproveExperienceList(experienceApprove);
            if (experienceApproveList.size() > 0) {
                for (EcardApiExperienceApprove approve : experienceApproveList) {
                    //数据解密（手机号、身份证号）
                    if (!StringUtils.objIsNullOrEmpty(approve.getExpPhone())) {
                        approve.setExpPhone(AESEncryptionUtils.decrypt(approve.getExpPhone(), salt));
                    }
                }
            }
            return experienceApproveList;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
